$(document).ready(function () {
	wszmcx.onLoad();
})

var wszmcx = (function () {
	var init = function () {
		//私有属性
		var curSeg;
		layui.use('form', function(){
		  var form = layui.form
		});
		layui.use('layer', function () {
			var layer = layui.layer;
		});
		$('#picCode').attr("src", 'https://wsbsfwt.ha-n-tax.gov.cn/cm/showPictureCode.do?t=' + Math.random());
	}
	return {
		onLoad: function () {
			init();
			wszmcx.reloadPicCode()
		},
		/*查询*/
		onQuery: function () {
			var shxydm = $(".qyshxydm").val().trim();
			var zmzg=$(".zmzg select").val().trim();
			var pzhm=$(".pzhm").val().trim();
			var rcode=$(".rcode").val().trim();
			if (shxydm != "" && pzhm != "" && rcode!="") {
				$.ajax({
					url: "https://wsbsfwt.ha-n-tax.gov.cn/taxclient/wssq/sszm/checkWswszm.do?",
					type: "GET",
					data: {
						SHXYDM:shxydm,
						ZH:zmzg,
						PZHM:pzhm,
						rcode:rcode
					},
					dataType: "jsonp",
					jsonpCallback: "wszmcx.onqueryCallback",
				});
			} else if(shxydm==""){
				layui.use('layer', function () {
					var layer = layui.layer;
					layer.msg('企业社会信用代码不能为空');
				});
			}else if(pzhm==""){
				layui.use('layer', function () {
					var layer = layui.layer;
					layer.msg('票证号查询不能为空');
				});
			}else if(rcode==""){
				layui.use('layer', function () {
					var layer = layui.layer;
					layer.msg('验证码不能为空');
				});
			}
		},
		onqueryCallback: function (jsonObj) {
			wszmcx.reloadPicCode();
			$(".rcode").val("");
			if(jsonObj.code=="0"){
					if ( $.fn.dataTable.isDataTable( '#wxlWszmcx' ) ) {
            		var table = $('#wxlWszmcx').DataTable();
            		table.destroy();
            	};
              	var data=[
	              {
	              	"ZMBH":jsonObj.ZMBH,
	              	"DYLX":jsonObj.DYLX,
	              	"SKSSJGMC":jsonObj.SKSSJGMC,
	              	"RKRQQ":jsonObj.RKRQQ,
	              	"RKRQZ":jsonObj.RKRQZ,
	              	"HJJE":jsonObj.HJJE
	              }
              	];
            	$('#wxlWszmcx').DataTable({
            		"data": data,
            		"columns": [{
            				"data": "ZMBH"
            			},
            			{
            				"data": "DYLX"
            			},
            			{
            				"data": "SKSSJGMC"
            			},
            			{
            				"data": "RKRQQ"
            			},
            			{
            				"data": "RKRQZ"
            			},
            			{
            				"data": "HJJE"
            			},
            		],
            		"ordering": false,
            		"info": false,
            		"lengthChange": false,
            		"searching": false
            	})
			}else{
				layer.msg(jsonObj.msg);
			}
			
		},
		winReset: function () {
			var nsrsbh = $(".wxl_cxSearch input").val("");
			$("#wxlWszmcx tbody").empty();
			wszmcx.reloadPicCode()
		},
		//验证码
        reloadPicCode: function () {
            // http://jcpt.ha-n-tax.gov.cn
            $('#picCode').attr("src", 'https://wsbsfwt.ha-n-tax.gov.cn/cm/showPictureCode.do?t=' + Math.random());
        }
	}
})();
